<cfcomponent>
	<cffunction name="getcomponents" access="public" returntype="query" hint="returns a query of installed components">
    	<cfargument name="cpath" default="#request.basepath#" required="no" hint="the path to where the components reside.">
        <cfdirectory action="list" directory="#cpath#components" type="dir" name="qcomponents">
        <cfreturn qcomponents>
    </cffunction>
	<cffunction name="getcomponentactions" access="public" returntype="query" hint="returns a query of actions available for this component">
      <cfargument name="c" required="yes" type="string" hint="component">
	  <cfif fileexists('#request.adminpath#components/#c#/switches/switchesxml.cfm')>
          <cffile action="read" file="#request.adminpath#components/#c#/switches/switchesxml.cfm" variable="readxml">
          <cfset menuxml = XmlParse(readxml)>
          <cf_xmlq name = "qactions" xpath = "/switches/switch" xml = "#menuxml#">
       <cfelse>
       		<cfset qactions = querynew("aval,template")>
       </cfif>
       <cfreturn qactions>
    </cffunction>
	<cffunction name="getthemes" access="public" returntype="query" hint="returns a query of installed themes">
    	<cfdirectory action="list" directory="#request.basepath#themes" type="dir" name="qthemes">
        <cfreturn qthemes>
    </cffunction>
	<cffunction name="getlayouts" access="public" returntype="query" hint="returns a query of installed layouts">
    	<cfargument name="theme" required="yes" hint="The theme to get layouts for">
    	<cfdirectory action="list" directory="#request.basepath#themes/#theme#/layouts" type="dir" name="qlayouts">
        <cfquery name="qlayouts" dbtype="query">
        SELECT * FROM qlayouts WHERE name <> 'css'
        </cfquery>
        <cfreturn qlayouts>
    </cffunction>
	<cffunction name="getpages" access="public" returntype="query" hint="returns a query of pages available in the docs folder">
    	<cfdirectory action="list" directory="#request.basepath#docs" type="file" name="qpages">
        <cfreturn qpages>
    </cffunction>
    <cffunction name="getsettings" access="public" returntype="query">
		<cfquery name="qsettings" datasource="#request.dsn#">
        SELECT * FROM core_settings
        </cfquery>
		<cfreturn qsettings>
	</cffunction>
    <cffunction name="getstates" access="public" returntype="query">
		<cfquery name="qstates" datasource="#request.dsn#">
        SELECT * FROM core_states
        WHERE iso_three = 'USA'
        </cfquery>
		<cfreturn qstates>
	</cffunction>
    <cffunction name="getusers" access="public" returntype="query" hint="this is for admin users">
    	<cfargument name="userid" default="0" required="no" hint="Specified to retrieve info about one user">
		<cfquery name="qusers" datasource="#request.dsn#">
        SELECT * FROM core_admins
        <cfif userid GT 0>WHERE id = <cfqueryparam value="#userid#" cfsqltype="cf_sql_integer"></cfif>
        </cfquery>
		<cfreturn qusers>
	</cffunction>
    <cffunction name="getusergroups" access="public" returntype="query" hint="this is for admin users">
    	<cfargument name="groupid" default="0" required="no" hint="Specified to retrieve info about one group">
		<cfquery name="qusergroups" datasource="#request.dsn#">
        SELECT * FROM core_admins_types
        <cfif groupid GT 0>WHERE id = <cfqueryparam value="#groupid#" cfsqltype="cf_sql_integer"></cfif>
        </cfquery>
		<cfreturn qusergroups>
	</cffunction>
    <cffunction name="getgrouppermissions" access="public" returntype="query" hint="this is for admin users">
    	<cfargument name="groupid" default="0" required="yes" hint="Groups to retrieve permissions for">
		<cfquery name="qpermissions" datasource="#request.dsn#">
        SELECT * FROM core_admins_rules
        WHERE userlevel = <cfqueryparam value="#groupid#" cfsqltype="cf_sql_integer">
        </cfquery>
		<cfreturn qpermissions>
	</cffunction>
	<cffunction name="writesettings" returntype="string" description="Writes the settings file to the configuration folder">
	<cfargument name = "path" type="string" required="no" default="#request.basepath#" hint="Full path to the installation folder">
	<cfargument name = "cfdsn" type="string" required="no" default="#request.dsn#" hint="Coldfusion dsn of the settings">
        <cfquery name = "qsettings" datasource="#cfdsn#">
        SELECT * FROM core_settings
        </cfquery>

		<!---clear file--->
		<cffile action = "write" file="#path#config/settings.cfm" output="" mode="777">

		<!---write main settings--->
        <cfset col_list = qsettings.columnlist>
            
        <cfloop from="1" to = "#listlen(col_list)#" index="c">
            <cfset thiscol = listgetat(col_list, c)>
			<cfset requestvar = 'REQUEST.#thiscol#'>
            <cfset requestvar = lcase(requestvar)>
            <cfset requestval = 'qsettings.#thiscol#'>
            <cfset requestval = evaluate(requestval)>
            <cfset requestval = replace(requestval, "'", "", "ALL")>
            <cfset requestval = replace(requestval, '"', '', 'ALL')>
        
           <cfif NOT requestval CONTAINS "'">
				<cfset thisline = "<cfset #requestvar# = '#requestval#'>">
            <cfelse>
	            <cfset thisline = '<cfset #requestvar# = "#requestval#">'>
            </cfif>
            
            <cffile action = "append" file="#path#config/settings.cfm" output="#thisline#" addnewline="yes">
        </cfloop>
   
   	 <cfset outputmsg = 'OK'>
	 <cfreturn outputmsg>

	</cffunction>
	<cffunction name="writecsettings" returntype="string" description="Writes settings for component">
	<cfargument name = "c" type="string" required="yes" hint="component name">
	<cfargument name = "fname" type="string" required="no" default="settings.cfm" hint="name of file to write to in component config folder">
	<cfargument name = "fields" type="struct" required="no" default="#form#" hint="form collection">

	  <!---clear file--->
      <cffile action = "write" file="#request.basepath#components/#c#/config/#fname#" output="" mode="777">
      <!---write main settings--->
      <cfloop collection="#fields#" item="thiscol">
      <cfif NOT thiscol IS 'fieldnames' AND NOT thiscol IS 'submitbtn'>
	  <cfset requestvar = 'REQUEST.#c#.#thiscol#'>
      <cfset requestvar = lcase(requestvar)>
      <cfset requestval = 'fields.#thiscol#'>
      <cfset requestval = evaluate(requestval)>
      <cfset requestval = replace(requestval, "'", "", "ALL")>
      <cfset requestval = replace(requestval, '"', '', 'ALL')>
      <cfif NOT requestval CONTAINS "'">
        <cfset thisline = "<cfset #requestvar# = '#requestval#'>">
        <cfelse>
        <cfset thisline = '<cfset #requestvar# = "#requestval#">'>
      </cfif>
      <cffile action = "append" file="#request.basepath#components/#c#/config/#fname#" output="#thisline#" addnewline="yes" mode="777">
      </cfif>
      </cfloop>
   	 <cfset outputmsg = 'OK'>
	 <cfreturn outputmsg>
    </cffunction>
</cfcomponent>